<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
include_once("../../config.inc.php");
include_once(__Modules_Path."/ChangeTime.lib.php");
include_once("WebConfig.php");

$strTmp = "{ 'SNo' : '{ShowSerailNo}', 'OSNo' : '{ShowOSerailNo}', 'DTime' : '{ShowDateTime}', 'GID' : {ShowGID}, 'NN' : {ShowNN}, 'NS' : {ShowNS} }";

$arrGame = array();
$arrScore = array();
foreach($arrWeb as $k => $arrW){
	$strName = $arrW[0];
	$strDir = $arrW[1];

	include("/home/share/www/".$strDir."/secure/db.inc.php");

	$strSQL = "(select * from `bet_Gamble` where LottoID = 5 order by ID desc limit 10)
				union (select * from `bet_Gamble` where LottoID = 6 order by ID desc limit 10)
				union (select * from `bet_Gamble` where LottoID = 7 order by ID desc limit 10)
				union (select * from `bet_Gamble` where LottoID = 8 order by ID desc limit 10)
	";
	$RS = @PMA_mysql_query($strSQL, $$_Conn);
	if(PMA_mysql_num_rows($RS) == 0)continue;

	$arrGID = array();
	while($Rows = PMA_mysql_fetch_object($RS)){
		$arrGame[$Rows -> LottoID][$k][$Rows -> SerialNo] = $Rows;
		$arrGID[] = $Rows -> ID;
	}

	$strSQL = "select * from `bet_GambleScore` where `GambleID` in (".implode(",", $arrGID).")";
	$RS = @PMA_mysql_query($strSQL, $$_Conn);
	if(PMA_mysql_num_rows($RS) == 0)continue;

	while($Rows = PMA_mysql_fetch_object($RS)){
		$arrScore[$k][$Rows -> GambleID] = $Rows;
	}

	@mysql_free_result($RS);
	@mysql_close($$_Conn);
}

$arrLottoID = array(5, 6, 7, 8);
$strCon = "";
$arrCon = array();
foreach($arrLottoID as $intLID){
	$arrTmp  = array();
	foreach($arrGame[$intLID][0] as $intSNo => $objGame){
		$strTmp1 = $strTmp;
		$strTmp1 = str_replace("{ShowSerailNo}", $objGame -> SerialNo, $strTmp1);
		$strTmp1 = str_replace("{ShowOSerailNo}", $objGame -> OSerialNo, $strTmp1);

		$strGDate = DateForm($objGame -> GameDate, $objGame -> GameTime, "Y-m-d");
		$strGTime = TimeForm($objGame -> GameDate, $objGame -> GameTime, "H:i:s");
		$strTmp1 = str_replace("{ShowDateTime}", $strGDate." ".$strGTime, $strTmp1);

		$arrNN = array();
		$arrNS = array();
		$arrGID = array();
		foreach($arrWeb as $k => $arrW){
			$intGID = $arrGame[$intLID][$k][$intSNo] -> ID;
			$arrNN[$k] = str_replace(",", ", &nbsp; ", $arrScore[$k][$intGID] -> NumberNormal);
			$arrNS[$k] = $arrScore[$k][$intGID] -> NumberSpecial;
			$arrGID[$k] = $k.":".$intGID;
		}
		$strTmp1 = str_replace("{ShowNN}", "['".implode("','", $arrNN)."']", $strTmp1);
		$strTmp1 = str_replace("{ShowNS}", "['".implode("','", $arrNS)."']", $strTmp1);
		$strTmp1 = str_replace("{ShowGID}", "['".implode("','", $arrGID)."']", $strTmp1);

		$arrTmp[] = $strTmp1;
	}
	$arrCon[] = "[ ".implode(",", $arrTmp)."]";
}
$strCon = "[ ".implode(",", $arrCon)."]";
WebOutputHTML($strCon, 1);
?>